﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = 13 Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If Len(TextBox1.Text) <> 0 Then
                Button1.Enabled = True
                Button1.Focus()
            Else
                MsgBox("Ingrese usuario", MsgBoxStyle.Critical)
                TextBox1.Focus()
            End If
        End If
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Dim resp = MsgBox("¿ Deseas salir de la aplicación ?", MsgBoxStyle.YesNo + MsgBoxStyle.Question)
        If resp = vbYes Then
            End
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim SQL As String = "select * from Usuarios where Usuario='" & TextBox1.Text & "'" & " AND Password='" & TextBox2.Text & "'"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            If dt.Rows.Count <> 0 Then
                Usuario = RTrim(dt.Rows(0)("Nombre")) & " " & RTrim(dt.Rows(0)("Apellido"))
                MDIParent1.Show()
                Me.Close()
            Else
                MsgBox("Usuario y/o password incorrectos", MsgBoxStyle.Critical)
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox1.Focus()
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class
